﻿using ETA.IRepository;
using ETA.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ETA.Service
{
    public class UploadFileService : IUploadFileService
    {
        #region 属性

        private IUploadFileRepository _IUploadFileRepository { set; get; }


        #endregion

        #region 构造函数

        public UploadFileService(IUploadFileRepository IUploadFileRepository)
        {
            _IUploadFileRepository = IUploadFileRepository;
        }

        #endregion

        public CreateUploadFileResponse CreateUploadFile(CreateUploadFileRequest req)
        {
            var res = new CreateUploadFileResponse();
            try
            {
                var file = _IUploadFileRepository.Insert(req.UploadFile);
                res.UploadFile = file;
                res.Result.IsSuccess = true;
            }
            catch (Exception e)
            {
                res.Result.IsSuccess = false;
                res.Result.ErrMessage = e.Message;
            }
            return res;
        }


        public QueryUploadFileResponse QueryUploadFileList(QueryUploadFileRequest req)
        {
            var response = new QueryUploadFileResponse();
            try
            {
                if (!string.IsNullOrEmpty(req.UploadFileId))
                {
                    response.UploadFileList = _IUploadFileRepository.GetAllList(b => b.UploadFileId == req.UploadFileId);
                }
                else
                {
                    response.UploadFileList = _IUploadFileRepository.GetAllList();
                }
                response.Result.IsSuccess = true;
            }
            catch (Exception e)
            {
                response.Result.Message = e.Message;
            }
            return response;
        }
    }
}
